<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>LIST CLASSES</title>
</head>
<link rel="stylesheet" type="text/css" href="/easyui/1.3.4/themes/default/easyui.css" />
<link rel="stylesheet" type="text/css" href="/css/wu.css" />
<link rel="stylesheet" type="text/css" href="/css/icon.css" />
<script type="text/javascript" src="/js/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="/js/jquery.validate.js"></script>
<script type="text/javascript" src="/easyui/1.3.4/jquery.easyui.min.js"></script>
<script type="text/javascript" src="/easyui/1.3.4/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="/js/jquery-form.js"></script>

<body>
	<c:if test="${activeUser.tid != -1 }">
		<table class="easyui-datagrid" style="width:700px;height:250px" id="dg_dishes_info1"
			data-options="fitColumns:true,border:false,fit:true,rownumbers:true,singleSelect:true,url:'<%=request.getContextPath()%>/addController/listClasses',method:'get',toolbar:toolbar,pagination:true">
		<thead>
			<tr>
				<th data-options="field:'cname',width:80">班级名称</th>
				<th data-options="field:'status',width:80,formatter:getClassStatus">班级状态</th>
				<th data-options="field:'tid_',width:80">教师</th>

			</tr>
		</thead>
	</table>
	</c:if>
	<c:if test="${activeUser.tid == -1 }">
		<table class="easyui-datagrid" style="width:700px;height:250px" id="dg_dishes_info1"
			data-options="fitColumns:true,border:false,fit:true,rownumbers:true,singleSelect:true,url:'<%=request.getContextPath()%>/addController/listClasses',method:'get',pagination:true">
		<thead>
			<tr>
				<th data-options="field:'cname',width:80">班级名称</th>
				<th data-options="field:'status',width:80,formatter:getClassStatus">班级状态</th>
				<th data-options="field:'tid_',width:80">教师</th>

			</tr>
		</thead>
	</table>
	</c:if>
	
	<script type="text/javascript">
		$(function(){
			$.ajax({
				type:"post",
				url:"<%=request.getContextPath()%>/addController/listByTeacher",
				dataType:"json",
				data:{},
				success:function(teacher){
					$("#tid").empty();
					for(var a in teacher){
						$("#tid").append("<option value='"+teacher[a].id+"'>"+teacher[a].name+"</option>")
					}
				}
				
			})
		})
	
		var toolbar = [{
			text:'添加班级',
			iconCls:'icon-add',
			handler:function(){
				$('#ff_dishes_info_add1').form("clear");
				$("#dlg_dishes_info_add").dialog("open");
			}
		
		}];
	</script>
	<div id="dlg_dishes_info_add" class="easyui-dialog" title="CLASSES" data-options="closed:true,iconCls:'icon-save'" style="width:300px;height:200px;padding:10px">
		<form id="ff_dishes_info_add1" action="<%=request.getContextPath() %>/addController/doAddClasses" method="post" >
	    	<table cellpadding="5">
	    		
	    		<tr>
	    			<td>班级名称:</td>
	    			<td><input type="text" class="easyui-textbox" name="cname" id="cname" ></input></td>
	    		</tr>
	    		
	    		<tr>
	    			<td>班级状态:</td>
	    			<td>
	    			<select name="status" id="status">
	    				<option value="1">当期</option>
	    				<option value="2">以往</option>
	    				<option value="3">返回</option>
	    			</select>
	    			</td>
	    		</tr>
	    		
	    		<tr>
	    			<td>讲师:</td>
	    			<td>
	    		<!-- 	<input class="easyui-combobox" name="tid" id="tid" data-options="valueField:'id',textField:'name',url:'<%=request.getContextPath()%>/addController/listByTeacher',
	    			panelHeight:'auto'" /> -->
	    			<select style="width: 140px;" name="tid" id="tid" >
	    				
	    			</select>
	    			
	    			</td>
	    		</tr>
	    		
	    	</table>
	    </form>
	    <div style="text-align:center;padding:5px">
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="submit_dishes_info_add()">提交</a>
	    	<a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearForm()">清空</a>
	    </div>
	</div>
	<script type="text/javascript">
	
	 <%--  $(function(){
		  	
		    $("#dlg_dishes_info_add").validate({
		    
		    	rules:{
		    		cname:{required:true,
		    				  remote:{
		    				  	url:"<%=request.getContextPath()%>/addController/Verification",
		    				  	type:"post",
		    				  	data:{
		    				  		cname:function(){
		    				  		 return $("#cname").val();
		    				  		}
		    				  	},
		    				  dataType:"json"
		    				  }
		    		        }
		    	    },
			    messages:{
					cname:{ 
						remote:"改班级已存在"
					  }
				}
		    
		    
		    })
		  
		  })
	 --%>
	
	
	function getClassStatus(value,row,index){
		//return "<input type='button' value='详情' onclick='openPanel("+row.id+")'/>";
		return value==1?"当期":value==2?"以往":"返回";
	}
	
	function aaa(){
			
			
	}
	
	
	function clearForm(){
		$("#ff_dishes_info_add1").form("clear");
		
	}
		function submit_dishes_info_add(){
			$("#ff_dishes_info_add1").form('submit',{
				url:"<%=request.getContextPath()%>/addController/doAddClasses",
				success:function (data){
					if(data){
						$.messager.show({
							title:'温馨提示',
							msg:'恭喜您！添加成功！',
							timeout:3000,
							showType:'slide'
						})
						$("#dlg_dishes_info_add").dialog("close");
						$("#dg_dishes_info1").datagrid("reload");
					}else{
						$.messager.show({
							title:'温馨提示',
							msg:'添加失败',
							timeout:3000,
							showType:'slide'
						})
					}
					
				}
			})
		}
			<%-- var cname = $("#cname").val();
			var status = $("#status").val();
			var tid = $("#tid").val();
			/* $("#ff_dishes_info_add1").ajaxSubmit({ */
				$.ajax({
				type:"post",
				url:"<%=request.getContextPath()%>/addController/doAddClasses?cname="+cname+"&status="+status+"&tid="+tid,
				dataType:"json",
			    success: function(flag){
			     	if(flag){
						$.messager.show({
							title:'温馨提示',
							msg:'恭喜您！添加成功！',
							timeout:3000,
							showType:'slide'
						});
						$("#dlg_dishes_info_add").dialog("close");
						$("#dg_dishes_info1").datagrid("reload");
					}else{
						$.messager.show({
							title:'温馨提示',
							msg:'对不起！添加失败！',
							timeout:3000,
							showType:'slide'
						});
					  $("#dg_dishes_info1").datagrid("reload");
					}
				}
			}); 
		}--%>
	</script>
	
</body>
</html>